﻿using Dx.Shared;
using JetBrains.Annotations;

namespace Dx.DDD.Domain.Entities
{
    [Serializable]
    public abstract class Entity : IEntity
    {
        protected Entity()
        {
            // EntityHelper.TrySetTenantId(this);
        }

        // <inheritdoc/>
        public override string ToString()
        {
            return "[ENTITY: " + GetType().Name + "] Keys = " + string.Join(",", GetKeys());
        }

        public abstract object[] GetKeys();
    }

    /// <inheritdoc cref="IEntity{TKey}" />
    [Serializable]
    public abstract class Entity<TKey> : Entity, IEntity<TKey>
    {
        /// <inheritdoc/>
        [CanBeNull]
        public virtual TKey?  Id { get; set; } 

        protected Entity()
        {

        }

        protected Entity([NotNull] TKey id)
        {
            Id = id;
        }

        public override object[] GetKeys()
        {
            return new object[] { Id??throw new ArgumentNullException(nameof(Id)) };
        }

        /// <inheritdoc/>
        public override string ToString()
        {
            return $"[ENTITY: {GetType().Name}] Id = {Id}";
        }
    }

}
